#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define LEN 10
#define SSN 20      // Social Security number

struct s_name {
    char first_name [LEN];
    char mid_name [LEN];
    char last_name [LEN];
};

struct person {
    char number [SSN];
    struct s_name name;
};

int is_empty(char * string);    // 检测是否是空字符串, 是则返回1 否则返回0
void print_info(struct person info[], int n);
void print_info2(struct person info);

int main(void)
{
    struct person info[5] = {
            {"B51414029", {"Jie", "Yu", "Zha"}},
            {"B51414010", {"Xiang", "Xiang", "Pan"}},
            {"B51414025", {"Jie", "Wen", "Jiang"}},
            {"B51414031", {"Ming", "Cheng", "Liu"}},
            {"B51414044", {"Qiang", " ", "Sha"}}
    };


    print_info(info, 5);
    printf("------------------------\n");
    for (int i = 0; i < 5; i++)
    {
        print_info2(info[i]);
    }
    return 0;
}

void print_info(struct person info[], int n)
{
    // Dribble, Flossie M. -- 302039823

    int i;

    for (i = 0; i < n; i++)
    {
        // 如果有中间名， 打印第一个字母 + .
        if (!is_empty(info[i].name.mid_name))
            printf("%s, %s %c. -- %s\n", info[i].name.first_name, info[i].name.last_name, info[i].name.mid_name[0], info[i].number);
        else // 如果没有中间名，不打印 .
            printf("%s, %s -- %s\n", info[i].name.first_name, info[i].name.last_name,  info[i].number);
    }
}

void print_info2(struct person info)
{
    if (!is_empty(info.name.mid_name))
        printf("%s, %s %c. -- %s\n", info.name.first_name, info.name.last_name, info.name.mid_name[0], info.number);
    else
        printf("%s, %s -- %s\n", info.name.first_name, info.name.last_name,  info.number);
}

// 判断是否是空字符串
int is_empty(char * string)
{
    int str_len = strlen(string);
    int i;

    for (i = 0; i < str_len; i++)
        if (!isspace(string[i]))
            return 0;
    return 1;
}